#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2002,2004 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#*===========================================================================*/
#*                                                                           */
#* Module Name:  recfgct                                                     */
#*                                                                           */
#* Description:                                                              */
#*      Script to reconfigure RSCT subsystems including reassigning node id  */
#*                                                                           */
#*===========================================================================*/
#  @(#)63   1.8   src/rsct/rmc/mcdaemon/recfgct.sh, mcdaemon, rsct_rzauh, rzauh0431a 2/17/03 18:23:04

# Set path to known value
PATH=/usr/sbin/rsct/install/bin:/usr/sbin/rsct/bin:/usr/bin:/bin:/usr/sbin
export PATH

# Get option arguments; 
#   -n means clean up the node id file (default option)
#   -s save the node id file.

cleannodeid=1
while getopts :ns opt
do
	case $opt in
                n) cleannodeid=1;;
                s) cleannodeid=0;;
        esac
done


#check the existence of /var/ct/cfg/*.ckpt
CKPTS=$(LC_ALL=C ls /var/ct/cfg/*.ckpt 2> /dev/null)

#check the existence of START_PORT_FILE
START_PORT_FILE=/var/ct/cfg/ctrmc.rpe   # rpe == remote port enable
if [[ -a $START_PORT_FILE ]]; then
    CTRMCRPE_EXIST=1
else
    CTRMCRPE_EXIST=0
fi

#check the existence of MSG_POLICY_FILE
MSG_POLICY_FILE=/var/ct/cfg/ctrmc.msgp
if [[ -s $MSG_POLICY_FILE ]]
then
	POLICY=$(< $MSG_POLICY_FILE)
else
	POLICY=
fi

#reconfigure RSCT
if [[ $cleannodeid -ne 0 ]]; then
	uncfgct -n
else
	uncfgct
fi

if [[ $CTRMCRPE_EXIST -ne 0 ]]; then
    # start the remote port if it was previously enabled (on next start of ctrmc)
    touch $START_PORT_FILE 
    chmod 440 $START_PORT_FILE
fi

#re-establish message policy
case $POLICY in
	R | E | D ) print $POLICY > $MSG_POLICY_FILE
				chmod 440 $MSG_POLICY_FILE
				;;
esac

cfgct

if [[ -n $CKPTS ]]; then
	# create this again for the ptf-reject
	touch $CKPTS
fi

exit 0
